package solution.queue;

public class Queue {
    private int maxSize;
    private int front;
    private int rear;
    private int[] arr;

    public Queue(int maxSize){
        this.maxSize = maxSize;
        front = -1;
        rear = -1;
        arr = new int[maxSize];
    }

    public boolean isEmpty(){
        return front == -1 && rear == -1;
    }

    public boolean isFull(){
        return rear == maxSize + 1;
    }

    public void push(int i){
        if (isFull()) throw new RuntimeException("队列已满");
        rear++;
        arr[rear] = i;
    }

    public int peek(){
        if (isEmpty()) throw new RuntimeException("队列为空");
        front++;
        return arr[front];
    }

    public int size(){
        int count = 0;
        for (int i : arr) {
            if (i != 0){
                count++;
            }
        }
        return count;
    }

    public int[] arr(){
        return arr;
    }
}
